home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / QuickTime / QuickTime VR / Make QTVR Object / DialogBox.c next >
Encoding:
Text File  |  2000-09-28  |  12.6 KB  |  425 lines  |  [TEXT/CWIE]

  1. //
  2. //         This is sample code which will make QTVR object movies from Linear QuickTime movies.
  3. //
  4. //        © 1991-1996 Apple Computer, Inc.  All rights reserved.
  5. //
  6.  
  7. #include "MakeQTVRObject.h"
  8. #include "extern.h" 
  9.  
  10.  
  11. #include <Dialogs.h>
  12.  
  13. void    InitDialogBox(DialogPtr    askBox,QTVRObjectFileFormat1x0Record    *fileFormat)
  14. {
  15.     Handle            iHandle;
  16.     short            iType;
  17.     Rect            iRect;
  18.     Str255            textStr;
  19.     
  20.     // Initialize dialog data items before display
  21.     GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
  22.     SetCtlValue ((ControlHandle) iHandle, fileFormat->movieType == kStandardObject);
  23.     
  24.     GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
  25.     SetCtlValue ((ControlHandle) iHandle, fileFormat->movieType == kOldNavigableMovieScene);
  26.     
  27.     GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
  28.     SetCtlValue ((ControlHandle) iHandle, fileFormat->movieType == kObjectInScene);
  29.     
  30.     NumToString (fileFormat->versionNumber, textStr);
  31.     GetDItem (askBox, iVersionNumber, &iType, &iHandle, &iRect);
  32.     SetIText (iHandle, textStr);
  33.     
  34.     FloatToString((float)(fileFormat->numberOfColumns),&textStr,0);
  35.     GetDItem (askBox, iNumberOfColumns, &iType, &iHandle, &iRect);
  36.     SetIText (iHandle, textStr);
  37.     
  38.     FloatToString((float)(fileFormat->numberOfRows),&textStr,0);
  39.     GetDItem (askBox, iNumberOfRows, &iType, &iHandle, &iRect);
  40.     SetIText (iHandle, textStr);
  41.     
  42.     FloatToString((float)(fileFormat->loopSize),&textStr,0);
  43.     GetDItem (askBox, iLoopSize, &iType, &iHandle, &iRect);
  44.     SetIText (iHandle, textStr);
  45.     
  46.     FloatToString((float)(fileFormat->loopTicks),&textStr,0);
  47.     GetDItem (askBox, iLoopTicks, &iType, &iHandle, &iRect);
  48.     SetIText (iHandle, textStr);
  49.     
  50.     FloatToString(Fix2Float(fileFormat->fieldOfView),&textStr,1);
  51.     GetDItem (askBox, iFieldOfView, &iType, &iHandle, &iRect);
  52.     SetIText (iHandle, textStr);
  53.     
  54.     FloatToString(Fix2Float(fileFormat->startHPan),&textStr,1);
  55.     GetDItem (askBox, iStartHPan, &iType, &iHandle, &iRect);
  56.     SetIText (iHandle, textStr);
  57.     
  58.     FloatToString(Fix2Float(fileFormat->endHPan),&textStr,1);
  59.     GetDItem (askBox, iEndHPan, &iType, &iHandle, &iRect);
  60.     SetIText (iHandle, textStr);
  61.     
  62.     FloatToString(Fix2Float(fileFormat->endVPan),&textStr,1);
  63.     GetDItem (askBox, iEndVPan, &iType, &iHandle, &iRect);
  64.     SetIText (iHandle, textStr);
  65.     
  66.     FloatToString(Fix2Float(fileFormat->startVPan),&textStr,1);
  67.     GetDItem (askBox, iStartVPan, &iType, &iHandle, &iRect);
  68.     SetIText (iHandle, textStr);
  69.  
  70. }
  71. //=================================================================================================
  72. // HandleMovieFormatDialog
  73. //-------------------------------------------------------------------------------------------------
  74. OSErr HandleMovieFormatDialog (MovieInstance    *theInstance,Boolean    applyValues)
  75. {
  76.     DialogPtr                        askBox;
  77.     Boolean                            boxDone = false;
  78.     Handle                            iHandle;
  79.     short                            hitItem,iType;
  80.     Rect                            iRect;
  81.     Str255                            textStr;
  82.     GWorldPtr                         saveGW;
  83.     GDHandle                         saveGD;
  84.     Boolean                            navControllerIsRunning = false,keepStartupViewInfo = false;
  85.     QTVRObjectFileFormat1x0Record    fileFormat;
  86.     OSErr                            err;
  87.     short                            versionNumber,movieType,numberOfColumns;
  88.     short                            numberOfRows,loopSize,loopTicks;
  89.     Fixed                            startHPan,endHPan,startVPan,endVPan;
  90.     Fixed                            fieldOfView,initialHPan,initialVPan;
  91.     TimeValue                        frameDur,posterViewTime;
  92.     QTVRObjectFileFormat1x0Record    currentObjectFormat;
  93.     UserItemUPP                        outlineUPP = nil;
  94.     ModalFilterUPP                    filterUPP = nil;
  95.     
  96.     askBox = GetNewDialog(kObjectDLOG, 0, (WindowPtr)-1);
  97.     if (!askBox) return (MemError());
  98.     InitCursor();
  99.     
  100.     outlineUPP = NewUserItemProc( OutlineOK );
  101.     filterUPP = NewModalFilterProc(ModalFilter);
  102.     
  103.     // Install the OK outlining userProc
  104.     GetDialogItem( askBox, 27, &iType, &iHandle, &iRect );
  105.     SetDialogItem( askBox, 27, iType, (Handle) outlineUPP, &iRect );
  106.     
  107.     GetGWorld(&saveGW, &saveGD);
  108.     SetGWorld((GWorldPtr)askBox,nil);
  109.     
  110.     if(!applyValues)
  111.         {
  112.         InitDialogBox(askBox, &gPrefInf.objectInfo);
  113.         SetWTitle (askBox, "\pSet Preferences");
  114.         }    
  115.     else
  116.         {
  117.         if(theInstance && theInstance->isObjectMovie)
  118.             {
  119.             GetQTVRObjectFileFormat1x0 (theInstance->movie,¤tObjectFormat);
  120.             InitDialogBox(askBox, ¤tObjectFormat);
  121.             }
  122.         else
  123.             InitDialogBox(askBox, &gPrefInf.objectInfo);
  124.         SetWTitle (askBox, "\pAdd Object Data");
  125.         }
  126.         
  127.     SelIText (askBox, iNumberOfRows, 0, 32767);        // Select the first text box
  128.     ShowWindow(askBox);
  129.     
  130.     while (!boxDone)
  131.         {
  132.         
  133.         ModalDialog(filterUPP, &hitItem);
  134.         GetDItem (askBox, hitItem, &iType, &iHandle, &iRect);
  135.         switch (hitItem) 
  136.             {
  137.             case iCancel:
  138.                 boxDone = true;
  139.                 break;
  140.             case iUseObject:
  141.                 {
  142.                 Movie    aMovie;
  143.                 FSSpec    aSpec;
  144.                 short    movieResFile,movieResID = 0;
  145.                 ControlHandle    aHandle;
  146.                 
  147.                 GetDItem (askBox, iOK, &iType, (Handle*)&aHandle, &iRect);
  148.                 if(GetAMovie(&aSpec))
  149.                     {
  150.                     err = OpenMovieFile(&aSpec,&movieResFile,fsRdPerm);
  151.                     if(err != noErr)
  152.                         {
  153.                         UserMessage("\pCould not open the movie.");
  154.                         break;
  155.                         }
  156.                     err = NewMovieFromFile(&aMovie,movieResFile,&movieResID,nil,0,nil);
  157.                     if(err != noErr)
  158.                         {
  159.                         UserMessage("\pCould not create movie from movie file.");
  160.                         break;
  161.                         }
  162.                     if(!GetQTVRObjectFileFormat1x0 (aMovie,¤tObjectFormat))
  163.                         InitDialogBox(askBox, ¤tObjectFormat);
  164.                     CloseMovieFile(movieResFile);
  165.                     }
  166.                 
  167.                 SetGWorld (saveGW,saveGD);
  168.                 OutlineOK(askBox,iOK );
  169.                 }
  170.                 break;
  171.             case iScene:
  172.                 SetCtlValue ((ControlHandle) iHandle, 1);
  173.                 GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
  174.                 SetCtlValue ((ControlHandle) iHandle, 0);
  175.                 GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
  176.                 SetCtlValue ((ControlHandle) iHandle, 0);
  177.                 break;
  178.             case iObjectInScene:
  179.                 SetCtlValue ((ControlHandle) iHandle, 1);
  180.                 GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
  181.                 SetCtlValue ((ControlHandle) iHandle, 0);
  182.                 GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
  183.                 SetCtlValue ((ControlHandle) iHandle, 0);
  184.                 break;
  185.             case iObject:
  186.                 SetCtlValue ((ControlHandle) iHandle, 1);
  187.                 GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
  188.                 SetCtlValue ((ControlHandle) iHandle, 0);
  189.                 GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
  190.                 SetCtlValue ((ControlHandle) iHandle, 0);
  191.                 break;
  192.             case iOK: 
  193.                 {
  194.                 long            num;
  195.                 
  196.                 boxDone = true;
  197.                 
  198.                 GetDItem (askBox, iVersionNumber, &iType, &iHandle, &iRect);
  199.                 GetIText (iHandle, textStr);
  200.                 if (textStr[0] == 0) boxDone = false;
  201.                 StringToNum (textStr, &num);
  202.                 versionNumber = num;
  203.                 
  204.                 GetDItem (askBox, iNumberOfColumns, &iType, &iHandle, &iRect);
  205.                 GetIText (iHandle, textStr);
  206.                 if (textStr[0] == 0) boxDone = false;
  207.                 StringToNum (textStr, &num);
  208.                 numberOfColumns = (short)StringToFloat (textStr);;
  209.                 
  210.                 GetDItem (askBox, iNumberOfRows, &iType, &iHandle, &iRect);
  211.                 GetIText (iHandle, textStr);
  212.                 if (textStr[0] == 0) boxDone = false;
  213.                 numberOfRows = (short)StringToFloat (textStr);;
  214.                 
  215.                 GetDItem (askBox, iLoopSize, &iType, &iHandle, &iRect);
  216.                 GetIText (iHandle, textStr);
  217.                 if (textStr[0] == 0) boxDone = false;
  218.                 loopSize = (short)StringToFloat (textStr);
  219.                 
  220.                 GetDItem (askBox, iLoopTicks, &iType, &iHandle, &iRect);
  221.                 GetIText (iHandle, textStr);
  222.                 if (textStr[0] == 0) boxDone = false;
  223.                 loopTicks = (short)StringToFloat (textStr);;
  224.                         
  225.                 GetDItem (askBox, iStartHPan, &iType, &iHandle, &iRect);
  226.                 GetIText (iHandle, textStr);
  227.                 if (textStr[0] == 0) boxDone = false;
  228.                 startHPan = Float2Fix(StringToFloat (textStr));
  229.                 
  230.                 GetDItem (askBox, iEndHPan, &iType, &iHandle, &iRect);
  231.                 GetIText (iHandle, textStr);
  232.                 if (textStr[0] == 0) boxDone = false;
  233.                 endHPan = Float2Fix(StringToFloat (textStr));
  234.                 
  235.                 GetDItem (askBox, iStartVPan, &iType, &iHandle, &iRect);
  236.                 GetIText (iHandle, textStr);
  237.                 if (textStr[0] == 0) boxDone = false;
  238.                 startVPan = Float2Fix(StringToFloat (textStr));
  239.                 
  240.                 GetDItem (askBox, iEndVPan, &iType, &iHandle, &iRect);
  241.                 GetIText (iHandle, textStr);
  242.                 if (textStr[0] == 0) boxDone = false;
  243.                 endVPan = Float2Fix(StringToFloat (textStr));
  244.                 
  245.                 GetDItem (askBox, iFieldOfView, &iType, &iHandle, &iRect);
  246.                 GetIText (iHandle, textStr);
  247.                 if (textStr[0] == 0) boxDone = false;
  248.                 fieldOfView = Float2Fix(StringToFloat (textStr));
  249.                 
  250.                 GetDItem (askBox, iObject, &iType, &iHandle, &iRect);
  251.                 if (GetCtlValue ((ControlHandle) iHandle)) movieType = kStandardObject;
  252.                 GetDItem (askBox, iScene, &iType, &iHandle, &iRect);
  253.                 if (GetCtlValue ((ControlHandle) iHandle)) movieType = kOldNavigableMovieScene;
  254.                 GetDItem (askBox, iObjectInScene, &iType, &iHandle, &iRect);
  255.                 if (GetCtlValue ((ControlHandle) iHandle)) movieType = kObjectInScene;
  256.                 
  257.                 initialHPan     = startHPan;
  258.                 initialVPan     = startVPan;
  259.                 if (theInstance) 
  260.                     {
  261.                     GetMovieNextInterestingTime (theInstance->movie, nextTimeMediaSample, 0, nil, 0, 1, nil, &frameDur);
  262.                     posterViewTime = MCGetCurrentTime (theInstance->movieController, nil);
  263.                     }
  264.                 
  265.                 if(boxDone)    
  266.                     {
  267.                     err = StuffQTVRObjectFileFormat1x0 (    movieType,
  268.                                                         frameDur,
  269.                                                         numberOfColumns,
  270.                                                         numberOfRows,
  271.                                                         loopSize,
  272.                                                         loopTicks,
  273.                                                         startHPan,
  274.                                                         endHPan,
  275.                                                         startVPan,
  276.                                                         endVPan,
  277.                                                         fieldOfView,
  278.                                                         initialHPan,
  279.                                                         initialVPan,
  280.                                                         &fileFormat);
  281.                     if(err)
  282.                         {
  283.                         boxDone = false;
  284.                         }
  285.                     else
  286.                         {
  287.                         gPrefInf.objectInfo = fileFormat;
  288.                         if (theInstance) 
  289.                             {
  290.                             ConvertTimeToPanUtil (posterViewTime,  
  291.                                                     fileFormat.frameDuration,
  292.                                                     fileFormat.numberOfColumns,
  293.                                                     fileFormat.numberOfRows,
  294.                                                     fileFormat.loopSize,
  295.                                                     fileFormat.startHPan,
  296.                                                     fileFormat.endHPan,
  297.                                                     fileFormat.startVPan,
  298.                                                     fileFormat.endVPan,
  299.                                                     &initialHPan, 
  300.                                                     &initialVPan);
  301.                             gPrefInf.objectInfo.initialHPan = fileFormat.initialHPan = initialHPan;
  302.                             gPrefInf.objectInfo.initialVPan = fileFormat.initialVPan = initialVPan;
  303.                             }
  304.                         }
  305.                     }
  306.                 else
  307.                     {
  308.                     // Only reson for a failure at this point is a missing parameter
  309.                     UserMessage("\pYou must fill in values for all parameters.");
  310.                     }
  311.                 
  312.                 
  313.                 if(boxDone && applyValues) SetQTVRObjectFileFormat1x0 (theInstance->movie,
  314.                                                                         theInstance->movieResFile,
  315.                                                                         theInstance->movieResID,
  316.                                                                         theInstance->spec,
  317.                                                                         posterViewTime,
  318.                                                                         &fileFormat);
  319.                 }
  320.                 break;
  321.             }
  322.         }
  323.     
  324.             
  325.         
  326.         
  327.  
  328.     DisposeDialog (askBox);
  329.     DisposeRoutineDescriptor(filterUPP);
  330.     DisposeRoutineDescriptor(outlineUPP);
  331.     SetGWorld (saveGW,saveGD);
  332.  
  333.     // Be really safe.  Close and open the movie again so the user can verify if anything is wrong.
  334.     if ((hitItem == iOK) && (err == noErr) && theInstance) {
  335.         FSSpec movieSFFile = theInstance->spec;        // Make a copy since we will close the window
  336.         CloseMovie (FrontWindow());                        // We know there is a FrontWindow
  337.         err = OpenMovie (&movieSFFile);
  338.     }
  339.     // BTW, the user should set the startup view after they have entered the nav data.
  340.     if(hitItem == iCancel) err = 1;
  341.     return (err);
  342. }
  343.  
  344.  
  345.  
  346. pascal Boolean ModalFilter(DialogPtr theDlg,EventRecord    *theEvent,short    *itemHit)
  347. {
  348.     switch(theEvent->what)
  349.         {
  350.         case mouseDown:
  351.             {
  352.             WindowPtr    whichWindow;
  353.             short int    thePart;
  354.     
  355.             thePart = FindWindow(theEvent->where, &whichWindow);
  356.             if(thePart == inDrag && whichWindow == theDlg)
  357.                 {
  358.                 DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
  359.                 return true;
  360.                 }
  361.             return false;
  362.             }
  363.             
  364.             break;
  365.         case keyDown:
  366.             {
  367.             char    theKey;
  368.             Handle    iHandle;
  369.             short    iType;
  370.             Rect    iRect;
  371.             
  372.             theKey = (theEvent->message & charCodeMask);
  373.             if(theKey == 0x03 || theKey == 0x0D)
  374.                 {
  375.                 *itemHit = iOK;
  376.                 GetDItem (theDlg, iOK, &iType, &iHandle, &iRect);
  377.                 HiliteControl ((ControlHandle)iHandle, true);
  378.                 Delay(8,nil);
  379.                 HiliteControl ((ControlHandle)iHandle, false);
  380.                 return true;
  381.                 }
  382.             if((theKey == '.' && ((theEvent->modifiers & cmdKey) != 0) ) || theKey == 0x1b)
  383.                 {
  384.                 GetDItem (theDlg, iCancel, &iType, &iHandle, &iRect);
  385.                 HiliteControl ((ControlHandle)iHandle, true);
  386.                 Delay(8,nil);
  387.                 HiliteControl ((ControlHandle)iHandle, false);
  388.                 *itemHit = iCancel;
  389.                 return true;
  390.                 }
  391.             }
  392.             break;
  393.         case updateEvt:
  394.             BeginUpdate (theDlg);
  395.             DrawDialog(theDlg);
  396.             EndUpdate (theDlg);
  397.             return false;
  398.             break;
  399.         }
  400.     
  401.     return false;
  402. }
  403.  
  404.  
  405.  
  406. pascal void OutlineOK(WindowPtr theDlg,short theItem )
  407. {
  408.     Rect    iRect;
  409.     Handle    iHndl;
  410.     short    iType;
  411.     Point    theOff = {0,0};
  412.     GWorldPtr                         saveGW;
  413.     GDHandle                         saveGD;
  414.     
  415.     GetGWorld(&saveGW, &saveGD);
  416.     SetGWorld((GWorldPtr)theDlg,nil);
  417.     GetDItem (theDlg, theItem, &iType, &iHndl, &iRect );
  418.     InsetRect( &iRect, -4,-4);
  419.     PenSize( 3,3 );
  420.     FrameRoundRect( &iRect, 16,16 );
  421.     PenSize( 1,1 );
  422.     SetGWorld (saveGW,saveGD);
  423. }
  424.  
  425.